package com.example.demo.service;

import java.util.List;

import org.springframework.stereotype.Service;

import com.example.demo.entity.ClassRoom;
import com.example.demo.mapper.ClassRoomMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import jakarta.annotation.Resource;

@Service
public class ClassRoomService {

    @Resource
    private ClassRoomMapper classRoomMapper;
    /**
     * 查询所有教室信息
     * @return 教室列表
     */
    public List<ClassRoom> selectAll(ClassRoom classRoom) {
        return classRoomMapper.selectByPage(classRoom);    
    }

    /**
     * 分页查询教室信息
     * @param classRoom 查询条件
     * @param pageNum 页码
     * @param pageSize 每页显示数量
     * @return 分页后的教室列表
     */
    public PageInfo<ClassRoom> selectByPage(ClassRoom classRoom, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<ClassRoom> list = classRoomMapper.selectByPage(classRoom);
        return PageInfo.of(list);
    }

    /**
     * 添加新教室
     * @param classRoom 教室对象，包含教室名称、座位数量、描述信息
     * @return 受影响的行数
     */
    public int insert(ClassRoom classRoom) {
        return classRoomMapper.insert(classRoom);
    }

    /**
     * 更新教室信息
     * @param classRoom 教室对象，包含ID、教室名称、座位数量、描述信息
     * @return 受影响的行数
     */
    public int update(ClassRoom classRoom) {
        return classRoomMapper.update(classRoom);
    }
    /**
     * 删除教室信息
     * @param idList 教室ID列表
     * @return 受影响的行数
     */
    public int delete(List<Integer> idList) {
        return classRoomMapper.delete(idList);
    }
}
